<?php
/**
 * Created by PhpStorm.
 * User: wdt
 * Date: 2016/3/29
 * Time: 18:28
 */

namespace front\modules\web\controllers;


use front\controllers\WebBaseController;
use goods\services\ShopCategoryProductService;
use yii\helpers\ArrayHelper;

class SearchController extends WebBaseController{

    public $layout = 'main';

    /**
     * 搜索页面
     * @return string
     */
    public function actionIndex()
    {
        return $this->render('index');
    }

    /**
     * 搜索结果商品列表
     * @return string
     */
    public function actionList()
    {
        $keyWords = \Yii::$app->request->get('keyWords');
        //去除用户输入的空格
        $keyWords = str_replace(' ','',$keyWords);
        $data = ShopCategoryProductService::searchList(['name' => $keyWords]);
        $data = ArrayHelper::toArray($data);
        return $this->render('list', [
                'value' => $keyWords,
                'data' => $data,
            ]);
    }
}